package com.dd.controller;

import com.dd.common.aop.annation.Login;
import com.dd.common.response.Result;
import com.dd.common.utils.HttpUtils;
import com.dd.pojo.entry.UserFoldFile;
import com.dd.service.RecycleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/recycle")
@RequiredArgsConstructor
@Api(tags = "回收站")
public class RecycleController {
    private final RecycleService recycleService;


    @PostMapping("/findRecycleFile")
    @ApiOperation("查看回收站文件")
    @Login
    public Result<?> findRecycleFile (HttpServletRequest request){
        String id = HttpUtils.anasyUserId(request);
        List<UserFoldFile> recycleFile = recycleService.findRecycleFile(id);
        return Result.success(recycleFile);
    }

    @PostMapping("/ReRecycleFile")
    @ApiOperation("恢复回收站文件")
    @Login
    public Result<?> ReRecycleFile (@ApiParam(name = "fileMd5",value = "fileMd5")
                                   @RequestParam("fileMd5") String fileMd5, HttpServletRequest request){
        String id = HttpUtils.anasyUserId(request);
        recycleService.ReRecycleFile(fileMd5,id);
        return Result.success();
    }

    @PostMapping("/DelRecycleFile")
    @ApiOperation("删除回收站文件")
    @Login
    public Result<?> DelRecycleFile(@ApiParam(name = "fileMd5",value = "fileMd5")
                                   @RequestParam("fileMd5") String fileMd5, HttpServletRequest request){
        String id = HttpUtils.anasyUserId(request);
        recycleService.DelRecycleFile(fileMd5,id);
        return Result.success();
    }
}
